package com.base.syslib.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;

public class SequenceId {
    private static final Log log = LogFactory.getLog(SequenceId.class);
    private Date dt = null;
    static private Random rand = null;

    public String getSequence() {
        dt = Calendar.getInstance().getTime();//如果不需要格式,可直接用dt,dt就是当前系统时间
        DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//设置显示格式
        String nowTime;
        nowTime = df.format(dt);
        if (rand == null) {
            rand = new Random();
        }
        String r1 = (String.valueOf(rand.nextLong())).substring(2, 7);
        return nowTime + r1;
    }

}
